<%--
  Created by IntelliJ IDEA.
  User: 123
  Date: 2020/11/18
  Time: 9:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

</head>
<body>
    <table border="1px" id="c">
        <tr>
            <td>ID</td>
            <td>主题</td>
            <td>内容</td>
            <td>时间</td>
            <td>操作</td>
        </tr>
    </table>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
<script type="text/javascript">
    $.ajax({
        url:"${pageContext.request.contextPath}/Newes",
        type:"get",

        success:function (date) {
            for (var i = 0; i < date.length;i++) {
                console.log(date[i].id)
                $("#c").append("<tr>\n" +
                    "            <td>" + date[i].id + "</td>\n" +
                    "            <td>" + date[i].title + "</td>\n" +
                    "            <td>" + date[i].content + "</td>\n" +
                    "            <td>" + date[i].createtime + "</td>\n" +
                    "            <td><a href='javascript:void(0)'onclick='doAjax("+date[i].id+",this)'>删除</a></td>\n" +
                    "        </tr>");
            }
        }
    })
    function doAjax(c,obj) {
        console.log(c)
        $.ajax({
            url:"${pageContext.request.contextPath}/Newes/"+c,
            type:"delete",
            success:function (date) {
                console.log(date)
                if(date.code="success"){
                    $(obj).parent().parent().remove();
                }
            }
        })
    }
</script>
</body>
</html>
